#pragma once
#include <afxcmn.h>

class ICEditCallBack
{
public:
    virtual void CEditCallBack(CString txt) = 0;
};

class CItemEdit : public CEdit
{
    ICEditCallBack* m_pICEditCallBack;
    DECLARE_MESSAGE_MAP()

public:
	CItemEdit(ICEditCallBack* _pICListCtrlEditCallBack)
		:m_pICEditCallBack(_pICListCtrlEditCallBack)
	{
	}

	void OnKillFocus(CWnd* pNewWnd)
	{
		CEdit::OnKillFocus(pNewWnd);

		CString txt;
		GetWindowText(txt);
		m_pICEditCallBack->CEditCallBack(txt);
		ShowWindow(SW_HIDE);
	}

	void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
	{
		if (nChar == VK_RETURN)
		{
			CString txt;
			GetWindowText(txt);
			m_pICEditCallBack->CEditCallBack(txt);
			ShowWindow(SW_HIDE);
		}
		CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
	}
};


class CEditListCtrl : public CListCtrl, public ICEditCallBack
{
	DECLARE_MESSAGE_MAP()
public:
	CEditListCtrl();
	~CEditListCtrl();
public:
	afx_msg void OnNMDblclk(NMHDR* pNMHDR, LRESULT* pResult);
	virtual void CEditCallBack(CString txt)
	{
		SetItemText(m_hitRow, m_hitCol, txt);
	}

	void SetEditable(BOOL bEditable = TRUE);
private:
	int m_hitCol;
	int m_hitRow;
	BOOL m_bEditable;
	CItemEdit* m_pEdit;
};

